<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><!-- bootstrap依赖 -->
<title>用户管理_新增页面</title>
<jsp:include page="/css/includeCSS.jsp">
	<jsp:param value="validator,formJ" name="csses"/>
</jsp:include>
</head>
<body>
	<div id="bodyTopDiv" style="margin-top: 20px;">
		<span class="label label-info">账户新增</span>
		<div style="padding: 0px 1% 15px; float: right;">
<!-- 			<button class="btn btn-info btn-sm" onclick="testUpload()" -->
<!-- 				id="testUploadButton">上传测试</button> -->
			<button class="btn btn-info btn-sm" onclick="submitForm()"
				id="submitButton">保存</button>
			<button class="btn btn-info btn-sm" onclick="deleteForm()"
				style="display: none;" id="deleteButton">删除</button>
			<button class="btn btn-info btn-sm" onclick="back()" id="backButton">关闭</button>
		</div>
	</div>
	<div class="container-fluid" style="margin-top: 20px;">
		<form id="jangleEditForm" name="jangleEditForm" class="form-horizontal" >
			<div class="form-group" >
				<label for="code" class="col-md-4 control-label">账户：</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="code" name="code" placeholder="请输入账户">
				</div>
			</div>
			<div class="form-group" >
				<label for="password"  class="col-md-4 control-label">密码：</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="password" name="password" placeholder="请输入密码">
				</div>
			</div>
			<div class="form-group" >
				<label for="name" class="col-md-4 control-label">名称：</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="name" name="name" placeholder="请输入名称">
				</div>
			</div>
			<input type="hidden" name="id" id="id">	<!-- 主键ID隐藏域 -->
			<input type="hidden" name="status" id="status" value="1">	<!-- 状态隐藏域 -->
		</form>
	</div>
	<jsp:include page="/js/includeJS.jsp">
		<jsp:param value="validator-out,utilJ" name="jses"/>
	</jsp:include>
	<script type="text/javascript" src="js/bsUserAdd.js?v=202312260850"></script>
	<script type="text/javascript">
		// 提交表单
		function submitForm() {
			$("#jangleEditForm").data("bootstrapValidator").validate(); //提交验证写法1
			// 			$("#jangleEditForm").bootstrapValidator("validate");		//提交验证写法2
			var valid = $("#jangleEditForm").data("bootstrapValidator")
					.isValid(); //验证通过返回true 不通过false
			if (!valid) {
				alert("请完善信息");
				return;
			}
			$.ajax({
				type:"POST",
				url : "/bsUserCtrl/insert.ctrl",
				dataType : "json",
				cache:false,
				data : $("#jangleEditForm").serialize(),
				error : function(request, textStatus, errorThrown) {
					jangleShowAjaxError(request, textStatus, errorThrown);
				},
				success : function(data) {
					success(data);		//执行成功后的判断，操作成功则返回列表页。
				}
			});
		}

		// dom加载完成之后
		$(function() {
			//TODO 这里添加其余逻辑
			
			if (!ps["id"]){
				return;
			}
			$.ajax({
				url : "/bsUserCtrl/selectByPrimaryKey.ctrl",
				dataType : "json",
				cache : false,
				data : {
					"id" : ps["id"]
				},
				error : function(request, textStatus, errorThrown) {
					jangleShowAjaxError(request, textStatus, errorThrown);
				},
				success : function(data) {
					if (data != null && data.code == "10001"
							&& data.model != null) {
						for ( var item in data.model) {
							$("#" + item).val(data.model[item]);
						}
						$("#deleteButton").show(); // 显示删除按钮
					}
				}
			});
		})
	</script>
</body>
</html>